package org.nnuer.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.nnuer.pojo.PatientExamAssignment;

import java.util.List;

@Mapper
public interface PatientExamAssignmentMapper{

    // 查询某患者所有未完成的分配
    @Select("SELECT * FROM patient_exam_assignment " +
            "WHERE patient_id = #{patientId} AND status = '待检查' " +
            "ORDER BY start_time ASC")
    List<PatientExamAssignment> listTodo(@Param("patientId") Long patientId);

    // 查询某设备当日待检查列表，用于计算排队长度
    @Select("SELECT * FROM patient_exam_assignment " +
            "WHERE device_id = #{deviceId} AND status = '待检查' " +
            "ORDER BY queue ASC")
    List<PatientExamAssignment> listQueue(@Param("deviceId") Long deviceId);

    // 把某个分配设为已完成
    @Update("UPDATE patient_exam_assignment " +
            "SET status = '已完成', finish_time = NOW() " +
            "WHERE patient_id = #{patientId} AND exam_id = #{examId}")
    void finishExam(@Param("patientId") Long patientId, @Param("examId") Long examId);
}